<?php
/**
 * Created by PhpStorm.
 * User: geolo
 * Date: 2018/10/10
 * Time: 10:21
 */
namespace app\modules\api\controllers;
use app\models\AgentGood;
use app\models\ShareGood;
use app\modules\api\models\AgentGoodForm;
use app\modules\api\models\ShareGoodForm;

class ChooseController extends Controller
{
    public function actionIndex()
    {
        $form = new AgentGoodForm();
        $form->attributes = \Yii::$app->request->get();

        $this->renderJson($form->getdata());
    }
    public function actionChoose()
    {
        $data = \Yii::$app->request->get();
        $store_id = $data['store_id'];
        $model = AgentGood::findOne([
            'store_id' => $store_id,
        ]);
        if(!$model){
            $model = new AgentGood();
        }
        if (\Yii::$app->request->isGet) {
            $form = new AgentGoodForm();
            $form->attributes = \Yii::$app->request->get();
            $form->model = $model;
            return $this->renderJson($form->save());
        }
    }
    public function actionChooseLive()
    {
        $data = \Yii::$app->request->get();
        $store_id = $data['store_id'];
        $model = ShareGood::findOne([
            'store_id' => $store_id,
        ]);
        if(!$model){
            $model = new ShareGood();
        }
        if (\Yii::$app->request->isGet) {
            $form = new ShareGoodForm();
            $form->attributes = \Yii::$app->request->get();
            $form->model = $model;
            return $this->renderJson($form->save());
        }
    }
}